package org.smartopen.unionpay.openapi.listener.mq;

import org.smartopen.unionpay.openapi.service.IMqService;
import org.springframework.web.client.RestTemplate;

/**
 * @Description: 业务通知MQ实现
 */
public interface IUnionPayNotify<T>  {

    int delayS[] = new int[]{60, 300, 3600, 6 * 3600, 12 * 3600};

    RestTemplate getRestTemplate();
    IMqService<T> getMqService();
    String getQueueName();

    default <K> String sendNotifyUrl(String notifyUrl, T body) {
        return getRestTemplate().postForObject(notifyUrl, body, String.class);
    }


    default void sendMessage(T message) {
        this.getMqService().sendMessage(getQueueName(), message);
    }

    default boolean sendMessage(T message, int count) {
        if (count > delayS.length) {
            return false;
        }
        this.getMqService().sendMessage(getQueueName(), message, delayS[count]);
        return true;
    }
}
